package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor " +
                    "FROM teacher t,class c " +
                    "WHERE t.id=c.teacher_id "+
                    "AND t.name='王克晶'";
           ResultSet rs =  statement.executeQuery(sql);
           while (rs.next()){
//               String name = rs.getString("t.name");
//               String gender = rs.getString("t.gender");
//               String className = rs.getString("c.name");
//               int floor = rs.getInt("floor");
               String name = rs.getString(1);
               String gender = rs.getString(2);
               String className = rs.getString(3);
               int floor = rs.getInt(4);
               System.out.println(name + ","+gender+","+className+","+floor);
           }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}